package com.sanqi;

import java.io.File;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.compress.utils.Lists;

import com.sanqi.work.util.SQUserUtil;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;

public class AdminTest {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(IdUtil.getSnowflakeNextIdStr());
        }
        
        System.out.println(SQUserUtil.getWorkUserTempLevel(DateUtil.parseDate("2025-08-15")));
//        delTableById();
        String extName = FileUtil.extName("C:\\Users\\duan\\Desktop\\aaaa.txt");
        System.out.println(extName);
        System.out.println(FileUtil.getParent(new File("C:\\Users\\duan\\Desktop\\aaaa.txt"), 1));
        System.out.println(new File("C:\\Users\\duan\\Desktop\\aaaa.txt").getParent());
        try {
            return ;
        } finally {
            System.out.println("22222222");
        }
    }
    
    
    
    
    private static void delTableById() {
        try {
            String tableName = "sva_log";
            int num = 500;
            String timeStr = "2025-08-01";
            Class.forName("com.mysql.cj.jdbc.Driver"); // MySQL数据库示例
            Connection connection = DriverManager.getConnection("jdbc:mysql://47.92.121.147:3705/coupon?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai"
                    , "root", "O)cBWSY@P2");
            PreparedStatement statement = connection.prepareStatement("select id from " + tableName +" where create_time < '" + timeStr + "'");
            ResultSet executeQuery = statement.executeQuery();
            
            List<String> ids = Lists.newArrayList();
            while(executeQuery.next()) {
                String string = executeQuery.getString(1);
                ids.add(string);
            }
            String sql = "delete from " + tableName + " where id in (";
            StringBuffer sqlBuffer = new StringBuffer("");
            for(int i = 0; i < num; i ++) {
                sqlBuffer.append("? ");
            }
            String sqlString = sqlBuffer.toString().trim();
            sqlString = sqlString.replace(' ', ',');
            sql += sqlString;
            sql += ")";
            List<List<String>> delList = Lists.newArrayList();
            int i = 0;
            List<String> restList = Lists.newArrayList();
            for (String id : ids) {
                if(i >= num) {
                    i = 0;
                    delList.add(restList);
                    restList = Lists.newArrayList();
                }
                restList.add(id);
                i ++;
            }
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            for (List<String> idList : delList) {
                int k = 1;
                for (String string : idList) {
                    preparedStatement.setString(k, string);
                    k ++;
                }
                System.out.println(preparedStatement.toString());
                preparedStatement.executeUpdate();
            }
            String restSql = "delete from  " + tableName + "  where id = ?";
            PreparedStatement restStatement = connection.prepareStatement(restSql);
            if(CollUtil.isNotEmpty(restList)) {
                for (String string : restList) {
                    restStatement.setString(1, string);
                    System.out.println(restStatement.toString());
                    restStatement.executeUpdate();
                }
            }
            System.out.println(DateUtil.formatDateTime(DateUtil.date()));
            preparedStatement.close();
            statement.close();
            restStatement.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
